package kvoog.arkanoid.common;

import java.util.HashMap;
import java.util.Map;

import com.artemis.Component;

/**
 * Represents a state for an EntityStateMachine. The state contains any number of ComponentProviders which
 * are used to add components to the entity when this state is entered.
 *
 * Ported from Ash entity component system framework for Action Script by Igor Knezevic. 
 * http://www.richardlord.net/blog/finite-state-machines-with-ash
 */
public class EntityState {

	/**
	 * Component type to provider dictionary.
	 */
	Map<Class<? extends Component>, IComponentProvider> providers = new HashMap<Class<? extends Component>, IComponentProvider>();

	/**
     * Add a new ComponentMapping to this state. The mapping is a utility class that is used to
     * map a component type to the provider that provides the component.
     *
     * @param type The type of component to be mapped
     * @return The component mapping to use when setting the provider for the component
     */
	public StateComponentMapping add(Class<? extends Component> type) {
		return new StateComponentMapping(this, type);
	}

	/**
     * Get the ComponentProvider for a particular component type.
     *
     * @param type The type of component to get the provider for
     * @return The ComponentProvider
     */
	public IComponentProvider get(Class<? extends Component> type) {
		return providers.get(type);
	}
	
	/**
	 * To determine whether this state has a provider for a specific component type.
	 *
	 * @param type The type of component to look for a provider for
	 * @return true if there is a provider for the given type, false otherwise
	 */
	public boolean has(Class<? extends Component> type) {
		return providers.containsKey(type); 
	}
}